#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<stack>
using namespace std;

class Solution {
public:
    bool isValid(string s)
    {
        stack<char> sk;
        int n = s.size();
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(' || s[i] == '[' || s[i] == '{')
            {
                sk.push(s[i]);
            }
            else
            {
                if (sk.empty())
                    return false;

                char top = sk.top();
                sk.pop();

                if (!((top == '(' && s[i] == ')')
                    || (top == '[' && s[i] == ']')
                    || (top == '{' && s[i] == '}')))
                {
                    return false;
                }
            }
        }
        if (!sk.empty())
        {
            return false;
        }
        else
        {
            return true;
        }
    }
};

int main()
{
    cout << Solution().isValid("[()]");

    return 0;
}